package com.yunhe.option.repository.data;

import com.yunhe.option.domain.data.GeneratePrice;
import org.springframework.data.neo4j.annotation.Query;
import org.springframework.data.neo4j.repository.Neo4jRepository;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

@Repository
public interface GeneratePriceRepository extends Neo4jRepository<GeneratePrice, Long> {

    @Query("Match (gp:GeneratePrice) where gp.title = {title} return gp")
    GeneratePrice findByTitle(@Param("title") String title);

    @Query("start s=Node({id}) match (s)-[]-(gp:GeneratePrice) return gp")
    Iterable<GeneratePrice> findByStationId(@Param("id") Long id);

    @Query("start gp=node({generatePriceId}), a=Node({areaId}) create (gp)-[:AREA_OF]->(a)")
    void bindArea(@Param("generatePriceId") Long generatePriceId, @Param("areaId") Long areaId);

    @Query("start s=Node({stationId}), p=Node({generatePriceId}) create (s)-[:HAS_GENERATE_PRICE]->(p)")
    void bindStation(@Param("stationId") Long stationId, @Param("generatePriceId") Long generatePriceId);
}
